<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/Product for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Product;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Product\Model\Product;
use Product\Model\Home;
use Product\Model\Detail;
use Product\Model\Category;
use Product\Model\DetailCatalog;
use Product\Model\Catalog;
use Product\Model\ProductCatalog;
use Product\Model\HomeTable;
use Product\Model\ProductTable;
use Product\Model\DetailTable;
use Product\Model\CategoryTable;
use Product\Model\CatalogTable;
use Product\Model\DetailCatalogTable;
use Product\Model\ProductCatalogTable;
use Product\Model\ProductTemplate;
use Product\Model\ProductTemplateTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

class Module implements AutoloaderProviderInterface
{
    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
		    // if we're in a namespace deeper than one level we need to fix the \ in the path
                    __NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
                ),
            ),
        );
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function onBootstrap(MvcEvent $e)
    {
        // You may not need to do this if you're doing it elsewhere in your
        // application
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
    }
	
	public function getServiceConfig()
     {
         return array(
             'factories' => array(
                 'Product\Model\HomeTable' =>  function($sm) {
                     $tableGateway = $sm->get('HomeTableGateway');
                     $table = new HomeTable($tableGateway);
                     return $table;
                 },
				 'Product\Model\ProductTable' =>  function($sm) {
                     $tableGateway = $sm->get('ProductTableGateway');
                     $table = new ProductTable($tableGateway);
                     return $table;
                 },
				 'Product\Model\DetailTable' =>  function($sm) {
                     $tableGateway = $sm->get('DetailTableGateway');
                     $table = new DetailTable($tableGateway);
                     return $table;
                 },
				 'Product\Model\CategoryTable' =>  function($sm) {
                     $tableGateway = $sm->get('CategoryTableGateway');
                     $table = new CategoryTable($tableGateway);
                     return $table;
                 },
				 'Product\Model\CatalogTable' =>  function($sm) {
                     $tableGateway = $sm->get('CatalogTableGateway');
                     $table = new CatalogTable($tableGateway);
                     return $table;
                 },
				 'Product\Model\DetailCatalogTable' =>  function($sm) {
                     $tableGateway = $sm->get('DetailCatalogTableGateway');
                     $table = new DetailCatalogTable($tableGateway);
                     return $table;
                 },
				 'Product\Model\ProductCatalogTable' =>  function($sm) {
                     $tableGateway = $sm->get('ProductCatalogTableGateway');
                     $table = new ProductCatalogTable($tableGateway);
                     return $table;
					 },
				 'Product\Model\ProductTemplateTable' =>  function($sm) {
                     $tableGateway = $sm->get('ProductTemplateTableGateway');
                     $table = new ProductTemplateTable($tableGateway);
                     return $table;
                 },
                 'DetailCatalogTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new DetailCatalog());
                     return new TableGateway('detailcatalog', $dbAdapter, null, $resultSetPrototype);
                 },
                 'CategoryTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Category());
                     return new TableGateway('productcategory', $dbAdapter, null, $resultSetPrototype);
                 },
                 
				 'CatalogTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Catalog());
                     return new TableGateway('catalogitem', $dbAdapter, null, $resultSetPrototype);
				 },	 
                 'HomeTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Home());
                     return new TableGateway('produks', $dbAdapter, null, $resultSetPrototype);
                 },
				 'ProductTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Product());
                     return new TableGateway('product', $dbAdapter, null, $resultSetPrototype);
					 
                 },
				 'DetailTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Detail());
                     return new TableGateway('details', $dbAdapter, null, $resultSetPrototype);
				 },
				 'ProductCatalogTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new ProductCatalog());
                     return new TableGateway('producttemplate', $dbAdapter, null, $resultSetPrototype);
					},
				 'ProductTemplateTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new ProductTemplate());
                     return new TableGateway('producttemplate', $dbAdapter, null, $resultSetPrototype);
					 
                 },
             ),
         );
     }
 }

